//
//  FQHomeProductTableViewCell.swift
//  SwiftProject
//
//  Created by 董駸 on 2023/4/14.
//

import UIKit

class FQHomeProductTableViewCell: BaseTableViewCell {

    let imageV = UIImageView()
    let titleLb = QMUILabel(font: .rSFont(15~), textColor: .color51)
    let rateLb = QMUILabel(font: .rSFont(12~), textColor: .color51)
    let limitLb = QMUILabel(font: .rSFont(12~), textColor: .color51)
    let numberLb = QMUILabel(font: .rSFont(13~), textColor: .color51)
    
    var model : FQOrganizationModel! {
        didSet {
            imageV.setAFImageWith(model.productIconLink, CGSize(width: 32~, height: 32~))
            titleLb.text = model.productName
            
            let rateStr : ASAttributedString = """
            \(model.loanMonth, .font(.rSFont(15~)), .foreground(.color149))\n贷款期限
            """
            rateLb.attributed.text = rateStr
            
            let limitStr : ASAttributedString = """
            \(model.loanAmount, .font(.mSFont(15~)), .foreground(.qmui_color(withHexString: "DE642C")!))\n可借额度
            """
            limitLb.attributed.text = limitStr
            
            let numberStr : ASAttributedString = """
            已放款\("\(model.numberOfLenders)", .foreground(.qmui_color(withHexString: "DE642C")!))人
            """
            numberLb.attributed.text = numberStr
        }
    }
    
    override var contentViewInset: UIEdgeInsets {
        UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        backgroundColor = .colorMake(252, 236, 221)
//        layer.cornerRadius = 8
//        clipsToBounds = true
        
        let colorV = UIView()
        colorV.backgroundColor = .white
        colorV.clipsToBounds = true
        colorV.layer.cornerRadius = 7.5
        contentView.addSubview(colorV)
        
        colorV.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.right.equalTo(-20)
            make.bottom.equalTo(-5)
            make.top.equalTo(5)
        }
        
        imageV.layer.cornerRadius = 4
        imageV.clipsToBounds = true
        colorV.addSubview(imageV)
        
        imageV.snp.makeConstraints { make in
            make.size.equalTo(32~)
            make.left.equalTo(16~)
            make.top.equalTo(14~)
        }
        
        colorV.addSubview(titleLb)
        titleLb.snp.makeConstraints { make in
            make.left.equalTo(imageV.snp.right).offset(12)
            make.centerY.equalTo(imageV)
            make.right.equalToSuperview().offset(-10)
        }
        
        let iconV = UIImageView(imageString: "icon_celllIcon")
        colorV.addSubview(iconV)
        
        iconV.snp.makeConstraints { make in
            make.right.bottom.equalToSuperview()
        }
        
        let button = QMUILabel(font: .rSFont(14~), textColor: .colorMain)
        button.text = "了解详情"
        button.layer.borderWidth = 1
        button.layer.borderColor = UIColor.colorMain.cgColor
        button.layer.cornerRadius = 4
        button.textAlignment = .center
        colorV.addSubview(button)
        
        button.snp.makeConstraints { make in
            make.right.equalTo(-14)
            make.size.equalTo(CGSize(width: 76, height: 28)~)
            make.bottom.equalTo(-16)
        }
        
        limitLb.numberOfLines = 0
        limitLb.textAlignment = .center
        colorV.addSubview(limitLb)
        
        limitLb.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.bottom.equalTo(-10~)
        }
        
        rateLb.numberOfLines = 0
        rateLb.textAlignment = .center
        colorV.addSubview(rateLb)
        
        rateLb.snp.makeConstraints { make in
            make.left.equalTo(limitLb.snp.right).offset(57)
            make.bottom.equalTo(-10~)
        }
        
        colorV.addSubview(numberLb)
        numberLb.snp.makeConstraints { make in
            make.right.equalTo(button)
            make.centerY.equalTo(titleLb)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
